﻿@model IEnumerable<WeProjectsModel.Resource>

@{
    ViewBag.Title = "Index";
}
<style type="text/css">
    .table tr th:last-child,
    .table tr td:last-child {
        max-width: 90px;
        text-align: center;
    }
    .table tr th a {
        color: #333 !important;
    }
    table td {
        padding-left: 10px;
        text-align: left !important;
    }
</style>
<h2>资源列表</h2>
@section Styles{
    <link href="@Href("~/Content/uploadify.css")" rel="stylesheet" />
}
@section scripts{
    <script src="@Href("~/Scripts/jquery.uploadify.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('#file_upload').uploadify({
                'fileSizeLimit':0,
                'swf': '@Url.Content("~/Scripts/uploadify.swf")',
                'uploader': '@Url.Content("~/Resource/Upload")',
                'auto': true,
                'multi': true,
                //'formData': {'archiveID':archiveID},
                'buttonText': '上传附件',
                'cancelImg': '@Url.Content("~/images/uploadify-cancel.png")',
                'onQueueComplete' : function(file, data, response) {
                    //alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
                    if (response != "OK")
                    {
                        //alert('The file ' + file.name + ' was failed to upload with a response of ' + response + ':' + data);
                    }
                    location.reload(true);
                }
            });
        });
    </script>
}
@if(Roles.IsUserInRole("sysadmin"))
{
    <input type="file" name="file_upload" id="file_upload" />
}

<div >
    @{
        var grid = new WebGrid(Model, defaultSort: "Title");
    }
    @grid.GetHtml(tableStyle:"table",columns: from c in grid.Columns(
                 grid.Column("Title", header: " 文件名 ", format: @<text>@Html.ActionLink((string)item.Title, "Download", "Resource", new { id = item.ID }, null)</text>,style:"thAction2"),
                 grid.Column("Size", header: " 文件大小（KB） "),
                 grid.Column("Description",header:"描述",format:@<text>@Html.Raw(item.Description)</text>),
                 grid.Column("UploadDateTime", header: " 最后修改时间 "),
                 grid.Column("Operation", header: "操作", format: @<text>@Html.ActionLink("详细", "Details", "Resource", new { id = item.ID }, new { @class = "btn btn-success btn-small marginR-10p" })
                 @if (Roles.IsUserInRole("sysadmin"))
                 {
                   @Html.ActionLink("编辑", "Edit", "Resource", new { id = item.ID }, new { @class = "btn btn-success btn-small marginR-10p" });<span> </span>
                   @Html.ActionLink("删除", "Delete", "Resource", new { id = item.ID }, new { @class = "btn btn-danger btn-small" });
                 } </text>, style: "thAction")
             )
                  //where !c.ColumnName.Contains("Operation") || (Roles.IsUserInRole("sysadmin"))
                  select c
    )
</div>


